home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS in a Box 7
/
BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso
/
Files
/
Prog
/
Q-R
/
Q&A.PAS
next >
Wrap
Pascal/Delphi Source File
|
1987-06-30
|
9KB
|
246 lines
TURBO PASCAL FOR THE MACINTOSH
Common Questions and Answers:
Q: Do I need Turbo to run programs I developed using Turbo?
A: No, you can create a "stand-alone" (double-clickable)
application by selecting the Compile To Disk item from the
Compile menu.
Q:What are the code and data limits for a Turbo Pascal program?
A:The Macintosh limits the code size of a program to 32K bytes.
You can overcome this limitation by segmenting your program.
This means you can have several 32K segments and you are the size
of your program is only by disk space. For more information on
segmenting see the Large Programs and Segmentation in chapter 9
and the Units and Large Programs section in chapter 8.
The Macintosh limits a program to 32K bytes of global data. To
overcome this limitation you can use pointers as in the following
sample:
program SaveSpace;
type
BigArray = array[1..$8000] of integer;
{ if we declared a variable of this type it would occupy 16K }
{ bytes. Half of our global data space!! }
var
SpaceSaver : ^BigArray;
i : integer;
begin
New(SpaceSaver); { allocate space for array off of the heap }
for i := to $8000 do
SpaceSaver^[i] := i; { index element by derefencing pointer }
end.
Q: How to a raise a number to a power?
A: Include the following function in your program:
function Raise(x, y : real) : real;
begin
Raise := exp(y * ln(x));
end; { Raise }
Q: How do I take the log base 10 of a number?
A: Include the following function in your program:
function Log(r : real) : real;
begin
Log := ln(r) / ln(10);
end;
Q: I am trying to call one of the Macintosh Toolbox routines
which takes a parameter of type PTR and I get a compiler error 44
(type mismatch) when I pass it a StringPtr. How can I get this
to compile?
A: Because of Pascal's strong typing rules, you can't directly
assign a value of type PTR for example to some other pointer
type. Instead, you have to coerce the pointer from one type to
another with variable type casts. For an example please refer to
the Variable-Type-Casts section at the end of chapter 19 in the
Turbo Refernce manual.
Q: I am writing a program that uses a "Macintosh Interface" but
when the program starts up a window flashes up on the screen and
then disappears. How do I get rid of this window altogether?
A: You are seeing is Turbo's PasConsole window which makes it
easy to set up text book programs. To eliminate PasConsole set
the {$U-} directive after your program statement.
Warning: Pasconsole initialize various Toolbox managers for you
so if you set {$U-} you must explicitily initialize these
managers. Please refer to the Initialization section in chapter
9 of the Turbo Pascal Reference Manual.
Q: I am trying to write a program using QuickDraw but its not
working. Nothing seems to be getting initialized as the
documentation in Inside Macintosh indicates. What is going
wrong?
A: If your program does not have the {$U-} directive, the
PasConsole unit will automatically used in your program.
Pasconsole defines and initializes its own set of QuickDraw
global variables to support the console window.
If your program uses both Pasconsole and QuickDraw, the QuickDraw
Unit's own set of global variables need to be initialized by
making the call InitGraf(@thePort). Before doing this however
you need to save the pointer to the PasConsole window or its
value will be wiped out InitGraf call as illustrated below.
Include the following procedure in your program and call it once
at the very beginning of your program.
procedure SetUpQuickDraw;
var
TurboPort : GrafPtr;
begin
GetPort(TurboPort); { Save the PasConsole window pointer }
InitGraf(@thePort);
SetPort(TurboPort); { Restore the PasConsole window pointer }
end;
Q: How do I generate random numbers with Turbo for the Mac? I
tried using QuickDraw's random number generator but I each time
the program runs it generates the same sequence of numbers even
though I change the value of RandSeed (the seed value used by the
genearator). What am I doing wrong?
A: RandSeed is a QuickDraw global variable so you need to
initialize this variable with the SetUpQuickDraw procedure listed
above. Below is a sample program that uses the system clock to
ensure that the program generates a different sequence of numbers
each time:
program RandomTest;
uses MemTypes, QuickDraw, OSIntf, ToolIntf;
var
i : integer;
begin
SetUpQuickDraw; { use the procedure listed above }
RandSeed := TickCount; { Set the seed to the time }
for i := 1 to 20 do
Writeln(abs(Random) mod i);
Readln;
end.
Q: How do I output text from my program to the printer?
A: You must include the PasPrinter unit and Write to the Printer
logical device as shown below:
program PrintTest;
uses PasPrinter;
begin
Writeln(Printer, 'Send this to the printer');
Close(Printer);
end.
Note: On LaserWriter printers you MUST close the Printer logical
device to get output.
Q: How do I do a screen dump to the printer? I want to print out
QuickDraw graphics as well as Turbo's Turtle graphics?
A: The following program demonstrates the Macintosh calls to
print the top folder on the screen and/or the whole screen:
program ScreenDump;
uses MemTypes, QuickDraw, OSIntf, ToolIntf, MacPrint;
procedure HardCopy(TopWindowOnly : boolean);
begin
PrDrvOpen;
if TopWindowOnly then
PrtCall(iPrEvtCtl, LprEvtTop, 0, LScreenBits)
else
PrtCall(iPrEvtCtl, LprEvtAll, 0, LScreenBits);
PrDrvrClose;
end; { HardCopy }
begin
HardCopy(true); { print Turbo's PasConsole window }
end.
Q: How do I find get more documentation on the procedures and
functions listed in the Macintosh Interfaces Units listed in
Appendix D of the Turbo Pascal Reference Manual?
A: Apple Computer's official documentation, INSIDE MACINTOSH, is
the most complete documentation on the Macintosh and its
Toolboxes.
Q: The Turbo Reference Manual it indicates you can shift text
left and right using the (clover)[ and (clover)] keys. I was
unable to shit the text in my program. Also these commands are
not highlighted on the Edit menu. What is wrong?
A: The text you highlight to be shifted must be made up of
complete lines of text. To mark a complete line move the mouse
to the leftmost column on the screen and select the text using
the click and drag method moving straight down the left side.
You should see the lines highlighted all the way across the
screen. You can then shift the (rectangular) block.
Q: Is there any way to stop a Turbo program short of hitting the
Reset button and restarting the machine which is very time consuming?
A: The following procedure sets up your system to allow you to
break out of a Turbo Pascal program without rebooting. On the
SAMPLES AND UTILITIES diskette in the MISCELLANEOUS folder there
is a file calles MACSBUG. If you put this file in your System
Folder and restart your system, the MACSBUG debugger will
automatically be loaded into memory. Now, whenever you need to
break out of a Turbo program press the interrupt switch (the
switch behind the reset switch on the left side of your
Macintosh, assuming you have installed the switches). This will
put you in the MacsBug debugger and you will see a ">" prompt.
At this prompt type ES and you will be returned to the Turbo
Environment.
Q: When I run my Turbo program it bombs bringing up a Macintosh
bomb box with Error 2. After hitting the Resume Error it goes
into the Turbo brings up an error message saying TARGET ADDRESS
FOUND IN UNIT placing the cursor at the end of my source file.
What is happening?
A: A system error 2 is an addressing error because some Macintosh
Toolbox routine is being passed an invalid pointer or handle.
Since the error is happening in one of these pre-compiled units
Turbo cannot take to the source line of the error. Make sure
that your program checks all error codes returned from Toolbox
routines and make sure no errors have occurred before proceeding.
Also refer to the chapter DEBUGGING YOUR TURBO PASCAL PROGRAM in
the Turbo Pascal Reference Manual.
Q: I am trying to port over some Turbo Pascal programs from the
IBM PC to Turbo Pascal for the Macintosh and I am getting
compiler errors. Why isn't Turbo for the Mac fully compatible?
A: Serious Pascal developers on the Macintosh have adopted the
Lisa Pascal standard. So it was necessary that Turbo Pascal
follows these standards. We have tried to also maintain close
compatibility with other implementations of Turbo Pascal. When
these standards conflict it was necessary that we adopt the Lisa
Pascal standard. For closer compatibility with the IBM PC
version of Turbo Pascal we have implemented a compatibility unit
that you can include in your programs. This unit is in a file
called Compat.inc in data library 5 of the Borland Programmers
Forum.